﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Kakeibo.Controller {
    class MainController : IController{
        private Model.KakeiboDatabase db_;
        private View.MainForm mainForm_;
        private List<IController> mainTabContentControllerList_;
        private List<IController> sideTabContentControllerList_;

        public MainController() {
            db_ = new Model.KakeiboDatabase();
            db_.Open("kakeibo.db");

            mainTabContentControllerList_ = new List<IController>();
            sideTabContentControllerList_ = new List<IController>();
            mainForm_ = new View.MainForm();

            AddMainTabContent("月計", new Controller.SummaryPanelController(db_));
            AddMainTabContent("test tab1", new GridPanelController(db_, null));
            AddMainTabContent("test tab2", new GridPanelController(db_, "kakeibo.debtor_sub_id = 10"));
            AddMainTabContent("test tab3", new GridPanelController(db_, "kakeibo.creditor_sub_id = 20"));

            mainForm_.OnClickImportDbMenuItem += OnClickImportDbMenuItem;
            mainForm_.OnClickExitMenuItem += OnClickExitMenuItem;
        }

        public View.IView View {
            get { return mainForm_; }
        }


        private void AddMainTabContent(string caption, IController controller){
            mainTabContentControllerList_.Add(controller);
            mainForm_.AddMainTabContent(caption, controller.View);
        }


        // event handler
        private void OnClickImportDbMenuItem(object sender, EventArgs e) {
            string path = mainForm_.showImportDbDialog();
            Model.KakeiboDatabaseConverter.ImportKokomaneDb(db_, path);
        }

        private void OnClickExitMenuItem(object sender, EventArgs e) {
            mainForm_.Close();
        }
    }
}
